package org.example.network;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;

public class Demo1 {

    public static void main(String[] args)
            throws IOException {
        InetAddress inetAddress = InetAddress.getLocalHost();
        System.out.println("inetAddress.getHostAddress() = " + inetAddress.getHostAddress());
        System.out.println("Arrays.toString(inetAddress.getAddress()) = "
                + Arrays.toString(inetAddress.getAddress()));
        InetAddress inetAddress1 = InetAddress.getByName("www.baidu.com");
        System.out.println("inetAddress1.getHostAddress() = " + inetAddress1.getHostAddress());
        System.out.println("Arrays.toString(inetAddress1.getAddress()) = "
                + Arrays.toString(inetAddress1.getAddress()));

        for (int i = 1; i < 255; i++) {
            final int ii = i;
            new Thread(()->{
                String ip = "192.168.1." + ii;
                InetAddress inetAddress2 = null;
                try {
                    inetAddress2 = InetAddress.getByName(ip);
                    if (inetAddress2.isReachable(100)) {
                        System.out.println(ip + " 可达");
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }).start();

        }

    }
}
